package com.vcit.common.core.domain.model;


import com.alibaba.fastjson2.annotation.JSONField;

import com.vcit.common.core.domain.entity.TStudent;
import com.vcit.common.utils.spring.SpringUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;

/**
 * 学生登录用户身份权限
 */

public class StudentLoginUser extends LoginUser {
    /**
     * 学生ID
     */
    private Long id;

    /**
     * 学生唯一标识
     */
    private String token;

    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private Long expireTime;

    /**
     * 登录IP地址
     */
    private String ipaddr;

    /**
     * 登录地点
     */
    private String loginLocation;

    /**
     * 浏览器类型
     */
    private String browser;

    /**
     * 操作系统
     */
    private String os;

    /**
     * 权限列表
     */
    private Set<String> permissions;


    /**
     * 学生信息
     */
    private TStudent student;


    public StudentLoginUser() {
    }

    public StudentLoginUser(TStudent student, Set<String> permissions) {
        this.student = student;
        this.permissions = permissions;
    }

    public StudentLoginUser(Long studentId, TStudent student, Set<String> permissions) {
        this.id = studentId;
        this.student = student;
        this.permissions = permissions;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.emptyList();
    }

    @JSONField(serialize = false)
    @Override
    public String getPassword() {
        PasswordEncoder passwordEncoder = SpringUtils.getBean(PasswordEncoder.class);
        return passwordEncoder.encode(student.getIdCard().substring(student.getIdCard().length()-6));
    }

    @Override
    public String getUsername() {
        return student.getStudentName();
    }

    @JSONField(serialize = false)
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JSONField(serialize = false)
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JSONField(serialize = false)
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JSONField(serialize = false)
    @Override
    public boolean isEnabled() {
        return true;
    }

    public Long getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Long loginTime) {
        this.loginTime = loginTime;
    }

    public String getIpaddr() {
        return ipaddr;
    }

    public void setIpaddr(String ipaddr) {
        this.ipaddr = ipaddr;
    }

    public String getLoginLocation() {
        return loginLocation;
    }

    public void setLoginLocation(String loginLocation) {
        this.loginLocation = loginLocation;
    }

    public String getBrowser() {
        return browser;
    }

    public void setBrowser(String browser) {
        this.browser = browser;
    }

    public String getOs() {
        return os;
    }

    public void setOs(String os) {
        this.os = os;
    }

    public Long getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Long expireTime) {
        this.expireTime = expireTime;
    }

    public Set<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(Set<String> permissions) {
        this.permissions = permissions;
    }

    public TStudent getStudent() {
        return student;
    }

    public void setStudent(TStudent student) {
        this.student = student;
    }


}